﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Dictionary;

namespace Dictionary.DataLayer
{
    public class ModifyDict
    {
        // Ham them bo tu dien moi
        public static bool AddNew(string fn,string name)
        {
            if (DataLayer.FileDir.CheckFile(DataLayer.FileDir.dirPath + "\\" + fn + ".xml") == true)
                return false;

            FileInfo fi = new FileInfo(DataLayer.FileDir.dirPath + "\\" + fn + ".xml");
            StreamWriter write = fi.CreateText();
            write.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            write.WriteLine("<!--EYES Dictionary-->");
            write.WriteLine("<Dictionary>");
            write.WriteLine("<Name>" + name + "</Name>");
            write.WriteLine("</Dictionary>");
            write.Close();
            return true;
        }

        //Ham xoa bo tu dien
        public static bool Delete(string fn)
        {
            if (DataLayer.FileDir.CheckFile(DataLayer.FileDir.dirPath + "\\" + fn) == true)
            {
                DataLayer.FileDir.DeleteFile(DataLayer.FileDir.dirPath + "\\" + fn);
                DataLayer.FileDir.DeleteFolder(BusLayer.LibsContent.GetDirImage() + "\\" + Path.GetFileNameWithoutExtension(fn));
                return true;
            }
            else
                return false;
        }
    }
}
